/**
 * @param {number[]} beans
 * @return {number}
 */
var minimumRemoval = function (beans) {
    beans.sort((a, b) => a - b);
    const n = beans.length;
    let sum = 0, mx = 0;
    for (let i = 0; i < n; i++) {
        // 总的魔法豆
        sum += beans[i];
        // 当前能剩下的魔法豆
        mx = Math.max(mx, (n - i) * beans[i]);
    }
    return sum - mx;

};